package com.cust.cow.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Configuration
@EnableSwagger2
@ComponentScan(basePackages = {"com.cust.cow.controller"})//配置扫描的基础包
public class Swagger{
    @Bean
    public Docket docket1(Environment environment){
        //选择显示的开发环境
        Profiles pro = Profiles.of("dev");
        //判断当前系统开发是否是开发环境
        boolean b = environment.acceptsProfiles(pro);
        return new Docket(DocumentationType.SWAGGER_2)
                //文档基础信息
                .apiInfo(getApiInfo())
                //忽略参数类型
                .ignoredParameterTypes(HttpSession.class, HttpServletRequest.class, HttpServletResponse.class)
                //选择接口路径
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.cust.cow.controller"))
                .build()
                //是否开启
                .enable(b)
                //分组名
                .groupName("肉牛管理系统接口文档");

    }
    private ApiInfo getApiInfo(){
        //联系人信息
        Contact contact =
                new Contact("张朋",
                        "cust.com",
                        "1435115476@qq.com");
        //Swagger文档基础配置
        ApiInfo info =
                new ApiInfo(
                        "肉牛管理系统接口文档",
                        "肉牛管理系统接口文档",
                        "v1.0",
                        "cust.cn",
                        contact,
                        "Apache2.0",
                        "",
                        new ArrayList<>()
                );
        return info;
    }

}